﻿using System;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Noria.Web.Utility
{
    internal class NHttpException : Exception
    {
        public NHttpException(HttpStatusCode status, string message)
            : base(message)
        {
            StatusCode = (int)status;
        }

        public NHttpException(HttpStatusCode status, string message, Exception innerException)
            : base(message, innerException)
        {
            StatusCode = (int)status;
        }

        public int StatusCode { get; private set; }

        public override string Message
        {
            get
            {
                return StatusCode + " - " + base.Message;
            }
        }

        public string Stringify()
        {
            JObject e = JObject.FromObject(new { error = Message });
            return e.ToString(Formatting.None);
        }
    }
}